#!/usr/bin/env bash
#      .-.     .-.     .-.     .-.     .-.     .-.
# `._.'   `._.'   `._.'   `._.'   `._.'   `._.'   `
#
# github.com/rafi herbstluftwm configuration

hc() {
	/opt/local/bin/herbstclient "$@"
}

hc emit_hook reload

# remove all existing keybindings
hc keyunbind --all

# keybindings
# if you have a super key you will be much happier with Mod set to Mod4
Mod=Mod2     # Use the super key as the main modifier
ModAlt=Mod1  # Use alt for bindings that conflict with OS

hc set focus_follows_mouse 1

hc keybind $Mod-Ctrl-q quit
hc keybind $Mod-Ctrl-r reload
hc keybind $Mod-Ctrl-c close
hc keybind $Mod-Return spawn /opt/local/bin/urxvtc -cd "$HOME"
hc keybind $Mod-F7 spawn /opt/local/bin/mpc prev
hc keybind $Mod-F8 spawn /opt/local/bin/mpc toggle
hc keybind $Mod-F9 spawn /opt/local/bin/mpc next
hc keybind $Mod-Shift-F7 spawn /opt/local/bin/mpc seek -10
hc keybind $Mod-Shift-F8 spawn /opt/local/bin/mpc stop
hc keybind $Mod-Shift-F9 spawn /opt/local/bin/mpc seek +10

# basic movement
# focusing clients
hc keybind $Mod-h     focus left
hc keybind $Mod-j     focus down
hc keybind $Mod-k     focus up
hc keybind $Mod-l     focus right

# moving clients
hc keybind $Mod-Shift-h     shift left
hc keybind $Mod-Shift-j     shift down
hc keybind $Mod-Shift-k     shift up
hc keybind $Mod-Shift-l     shift right

# splitting frames
# create an empty frame at the specified direction
hc keybind $Mod-Ctrl-g  split   right   0.5
hc keybind $Mod-Ctrl-v  split   bottom  0.5
# let the current frame explode into subframes
hc keybind $Mod-Ctrl-space split explode

# resizing frames
resizestep=0.05
hc keybind $Mod-Ctrl-h  resize left +$resizestep
hc keybind $Mod-Ctrl-j  resize down +$resizestep
hc keybind $Mod-Ctrl-k  resize up +$resizestep
hc keybind $Mod-Ctrl-l  resize right +$resizestep

# layouting
hc keybind $Mod-r remove
hc keybind $Mod-x cycle_layout 1
hc keybind $Mod-t floating toggle
hc keybind $Mod-f fullscreen toggle
hc keybind $Mod-p pseudotile toggle

# mouse
hc mouseunbind --all
hc mousebind $Mod-Button1 move
hc mousebind $Mod-Button2 zoom
hc mousebind $Mod-Shift-Button1 resize

# focus
hc keybind $ModAlt-Tab        cycle_all +1
hc keybind $ModAlt-Shift-Tab  cycle_all -1
hc keybind $Mod-BackSpace     cycle_monitor
hc keybind $Mod-c  cycle
hc keybind $Mod-i  jumpto urgent

# theme
hc attr theme.tiling.reset 1
hc attr theme.floating.reset 1
hc set frame_border_active_color '#222222'
hc set frame_border_normal_color '#101010'
hc set frame_bg_normal_color '#565656'
hc set frame_bg_active_color '#345F0C'
hc set frame_border_width 0
hc set always_show_frame 0
hc set frame_bg_transparent 0
hc set frame_transparent_width 0
hc set frame_gap 0

hc attr theme.active.color '#9fbc00'
hc attr theme.normal.color '#454545'
hc attr theme.urgent.color orange
hc attr theme.inner_width 1
hc attr theme.inner_color black
hc attr theme.border_width 2
hc attr theme.floating.border_width 4
hc attr theme.floating.outer_width 1
hc attr theme.floating.outer_color black
hc attr theme.active.inner_color '#3E4A00'
hc attr theme.active.outer_color '#3E4A00'
hc attr theme.background_color '#141414'

hc set window_gap 0
hc set frame_padding 0
hc set smart_window_surroundings 0
hc set smart_frame_surroundings 1
hc set mouse_recenter_gap 0

# rules
hc unrule -F
#hc rule class=XTerm tag=3 # move all xterms to tag 3
hc rule focus=on # normally focus new clients
#hc rule focus=off # normally do not focus new clients
# give focus to most common terminals
#hc rule class~'(.*[Rr]xvt.*|.*[Tt]erm|Konsole)' focus=on
hc rule class='Sxiv' pseudotile=on
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)' pseudotile=on
hc rule windowtype='_NET_WM_WINDOW_TYPE_DIALOG' manage=off
hc rule windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)' manage=off

# unlock, just to be sure
hc unlock

hc set tree_style '╾│ ├└╼─┐'

# do multi monitor setup here, e.g.:
# hc set_monitors 1280x1024+0+0 1280x1024+1280+0
# or simply:
#hc detect_monitors
#hc set_monitors 1440x900+0-23
hc set_monitors 1440x878+0-1

# Load urxvt-client and tmux on startup
/opt/local/bin/urxvtc -cd "$HOME" -e /opt/local/bin/tmux -f "$HOME/.config/tmux/config"

# vim: set ts=2 sw=2 tw=80 noet :
